package com.svs.web.controller.system;

import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.svs.common.config.Global;
import com.svs.framework.shiro.util.ShiroUtils;
import com.svs.framework.web.BackendController;
import com.svs.system.domain.SysDictData;
import com.svs.system.domain.SysMenu;
import com.svs.system.domain.SysUser;
import com.svs.system.service.SysDictDataService;
import com.svs.system.service.SysMenuService;

/**
 * 首页 业务处理
 * 
 * @author dujianqiao
 */
@Controller
public class SysIndexController extends BackendController
{
    @Autowired
    private SysMenuService menuService;
    
    @Autowired
	private SysDictDataService sysDictDataService;

    // 系统首页
    @GetMapping(value={"/index","/"})
    public String index(ModelMap mmap)
    {
        // 取身份信息
        SysUser user = getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", Global.getCopyrightYear());
        //根据用户情况给出首页地址
        boolean cityFlag = false;
        menus.forEach(tem->{
//        	if(StringUtils.isNotBlank(tem.getUrl)){
//        		
//        	}
        });
        String pcView = "index";
        String mView = "mobile/index";
        return goPage(pcView, mView);
    }

    // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap)
    {
//    		mmap.put("version", Global.getVersion());
//    		mmap.put("thisYear", Calendar.getInstance().get(Calendar.YEAR));
//		mmap.put("lastYear", Calendar.getInstance().get(Calendar.YEAR)-1);
//		//所有的类别
//		SysDictData category = new SysDictData();
//		category.setParentCode(0L);
//		category.setDictType(EnterpriseDataConstants.DICT_DATA_TYPE);
//		mmap.put("dataList", sysDictDataService.selectAllList(category));
//		if(ShiroUtils.getSubjct().isPermitted("project:enterpriseCityIndex:view")){
//	    		return "project/enterpriseIndex/cityIndex";
//	    	}else if(ShiroUtils.getSubjct().isPermitted("project:enterpriseAreaIndex:view")){
//	    		return "project/enterpriseIndex/areaIndex";
//	    	}
    	//根据当前用户的菜单权限来分配首页
        return "main";
    }
}
